import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  OneToOne,
  OneToMany,
  JoinColumn,
} from 'typeorm';
import { UserInfo } from './user_info.entity';
import { Friend } from './friend.entity';
@Entity()
export class User {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ unique: true })
  username: string;

  @Column({ select: false })
  password: string;

  @Column({
    name: 'create_time',
    type: 'timestamp',
    default: () => 'CURRENT_TIMESTAMP',
  })
  createTime: Date;

  @Column({
    name: 'update_time',
    type: 'timestamp',
    default: () => 'CURRENT_TIMESTAMP',
  })
  updateTime: Date;

  @OneToOne(() => UserInfo, (userInfo) => userInfo.user)
  userInfo: UserInfo;

  // 正在关注的
  @OneToMany(() => Friend, (friend) => friend.user)
  @JoinColumn()
  followings: { id: number }[];

  // 粉丝
  @OneToMany(() => Friend, (friend) => friend.follow)
  @JoinColumn()
  followers: { id: number }[];
}
